<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/25
 * Time: 15:32
 */
class Server
{
    const port = 8811;

    public function port()
    {
        $shell  = "netstat -anp 2>/dev/null | grep " . self::port . " | grep LISTEN | wc -l";
        $result = shell_exec($shell);
        if($result != 1){
            //发送报警服务，发短信、邮件
            echo date("Y-m-d H:i:s") . '-error' . PHP_EOL;
        }else{
            echo date("Y-m-d H:i:s") . '-success' . PHP_EOL;
        }
    }
}
//nohup
swoole_timer_tick(2000, function($timer_id){
    (new Server())->port();
});